<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class VersionController extends BaseController {

    //版本列表
	public function index() {

        $count = M('version')->count();
        $page = getpage($count,10);
        $version_arr = M('version')->order('version_id desc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('version_arr', $version_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

    //版本详情
    public function version_details(){
        $data['version_id'] = I('get.version_id');
        $version_arr = M('version')->where($data)->find();
        $this->assign('version_arr',$version_arr);
        $this->display();
    }

    //添加版本
    public function version_add(){
        if (I('post.action') == 'version_add_action') {
            unset($_POST['action']);
            $this->version_add_action();
            exit();
        }
        $this->display();
    }

    //添加版本操作
    public function version_add_action(){

        if($_POST != array_filter($_POST)){
            $this->error('选项不能有空值');
        }
        $_POST['version_createtime'] = time();

        if(M('version')->add($_POST)){
            $this->success('添加版本成功','index');
        }else{
            $this->error('添加版本失败');
        }

    }

    //修改版本信息
    public function version_edit(){
        if (I('post.action') == 'version_edit_action') {
            unset($_POST['action']);
            $this->version_edit_action();
            exit();
        }
        $data['version_id'] = I('get.version_id');
        $version_arr = M('version')->where($data)->find();
        $this->assign('version_arr',$version_arr);
        $this->display();
    }

    //修改版本信息操作
    public function version_edit_action(){

        M('version')->save($_POST);
        $this->success('操作完成','index');
    }

}